<?php
require_once $_SERVER['DOCUMENT_ROOT'].'/home/config.php';

$array_return = array();
$array_return['status'] = 0;
$array_return['html'] = '';

$rep_comment_id = getValue('rep_comment_id','int','POST',0);
$rep_email = getValue('rep_email','str','POST','',2);
$rep_name = getValue('rep_name','str','POST','',2);
$rep_content = getValue('rep_content','str','POST','',2);
if($rep_comment_id == 0 || $rep_email == '' || $rep_name == '' || $rep_content == '') {
   $array_return['html'] = 'Thiếu dữ liệu gửi đi';
}else {
   $db_in_rep = new db_execute('INSERT INTO comments_reply(rep_content,rep_name,rep_email,rep_comment_id,rep_date)
                                             VALUES("'.$rep_content.'","'.$rep_name.'","'.$rep_email.'",'.$rep_comment_id.','.time().')');
   $db_upfb = new db_execute('UPDATE comments SET com_date_feedback = '.time().' WHERE com_id = '.$rep_comment_id);

   if($db_in_rep->total) {
      setcookie('comment_name',$rep_name,time() + 86400,'/');
      setcookie('comment_email',$rep_email,time() + 86400,'/');
      $array_return['status'] = 1;
      $array_return['html'] = '<div class="reply_item">
                                 <img src="/themes/img/avatar_guest.jpg" alt="avatar guest comment" />
                                 <p class="cmt_name"><strong>'.$rep_name.'</strong></p>
                                 <p class="cmt_content">'.$rep_content.'</p>
                                 <p class="cmt_meta">
                                    <span class="cmt_like">Thích <i class="icon_like"></i> <span>0</span></span>
                                    <span class="cmt_date">vừa xong</span>
                                 </p>
                              </div>';
   }else {
      $array_return['status'] = 0;
      $array_return['html'] = 'Lỗi không xác định. Vui lòng thử lại sau.';
   }
}

die(json_encode($array_return));
?>